

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>安装k8s 环境部分 &mdash; python3-cookbook 3.0.0 documentation</title>
  

  
  
  
  

  

  
  
    

  

  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="第一章：数据结构和算法" href="../chapters/p01_data_structures_algorithms.html" />
    <link rel="prev" title="k8s 安装" href="../chapters/k8s.html" /> 

  
  <script src="../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../index.html" class="icon icon-home"> python3-cookbook
          

          
          </a>

          
            
            
              <div class="version">
                3.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="../chapters/k8s.html">k8s 安装</a><ul class="current">
<li class="toctree-l2 current"><a class="current reference internal" href="#">安装k8s 环境部分</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#api">其他所有配置等文件在 api 目录下</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id1">一 环境</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id2">二 准备环境</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../chapters/p01_data_structures_algorithms.html">第一章：数据结构和算法</a></li>
<li class="toctree-l1"><a class="reference internal" href="../chapters/p02_strings_and_text.html">第二章：字符串和文本</a></li>
<li class="toctree-l1"><a class="reference internal" href="../aboutme.html">关于</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">python3-cookbook</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../chapters/k8s.html">k8s 安装</a> &raquo;</li>
        
      <li>安装k8s 环境部分</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/c03/k8s.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="k8s">
<h1>安装k8s 环境部分<a class="headerlink" href="#k8s" title="Permalink to this headline">¶</a></h1>
<div class="section" id="api">
<h2>其他所有配置等文件在 api 目录下<a class="headerlink" href="#api" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="id1">
<h2>一 环境<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">master_1</span><span class="p">:</span> <span class="n">centos7</span>
<span class="n">node_1</span><span class="p">:</span> <span class="n">centos7</span>

<span class="n">docker</span><span class="p">:</span> <span class="mf">17.03</span>
<span class="n">k8s</span><span class="p">:</span>    <span class="mf">1.10</span>
<span class="n">etcd</span><span class="p">:</span>   <span class="mf">3.2</span><span class="o">.</span><span class="mi">15</span>
<span class="n">参考</span><span class="p">:</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">www</span><span class="o">.</span><span class="n">kubernetes</span><span class="o">.</span><span class="n">org</span><span class="o">.</span><span class="n">cn</span><span class="o">/</span><span class="mf">3808.</span><span class="n">html</span>
</pre></div>
</div>
</div>
<div class="section" id="id2">
<h2>二 准备环境<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><strong>1. 配置好各节点hosts文件</strong></li>
</ul>
<div class="code sh highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">hostnamectl</span> <span class="nb">set</span><span class="o">-</span><span class="n">hostname</span> <span class="n">master_1</span>
<span class="n">hostnamectl</span> <span class="nb">set</span><span class="o">-</span><span class="n">hostname</span> <span class="n">node_1</span>

<span class="n">cat</span> <span class="o">&lt;&lt;</span><span class="n">EOF</span> <span class="o">&gt;&gt;/</span><span class="n">etc</span><span class="o">/</span><span class="n">hosts</span>
<span class="mf">172.16</span><span class="o">.</span><span class="mf">54.167</span> <span class="n">master_1</span>
<span class="mf">172.16</span><span class="o">.</span><span class="mf">54.100</span> <span class="n">node_1</span>
<span class="mf">172.16</span><span class="o">.</span><span class="mf">54.165</span> <span class="n">etcd1</span>
<span class="n">EOF</span>
</pre></div>
</div>
<ul class="simple">
<li><strong>2. 关闭系统防火墙</strong></li>
</ul>
<div class="code sh highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">systemctl</span> <span class="n">stop</span> <span class="n">firewalld</span>
<span class="n">systemctl</span> <span class="n">disable</span> <span class="n">firewalld</span>
</pre></div>
</div>
<ul class="simple">
<li><strong>3. 关闭SElinux</strong></li>
</ul>
<div class="code sh highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">setenforce</span>  <span class="mi">0</span>
<span class="n">sed</span> <span class="o">-</span><span class="n">i</span> <span class="s2">&quot;s/^SELINUX=enforcing/SELINUX=disabled/g&quot;</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">sysconfig</span><span class="o">/</span><span class="n">selinux</span>
<span class="n">sed</span> <span class="o">-</span><span class="n">i</span> <span class="s2">&quot;s/^SELINUX=enforcing/SELINUX=disabled/g&quot;</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">selinux</span><span class="o">/</span><span class="n">config</span>
<span class="n">sed</span> <span class="o">-</span><span class="n">i</span> <span class="s2">&quot;s/^SELINUX=permissive/SELINUX=disabled/g&quot;</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">sysconfig</span><span class="o">/</span><span class="n">selinux</span>
<span class="n">sed</span> <span class="o">-</span><span class="n">i</span> <span class="s2">&quot;s/^SELINUX=permissive/SELINUX=disabled/g&quot;</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">selinux</span><span class="o">/</span><span class="n">config</span>
</pre></div>
</div>
<ul class="simple">
<li><strong>4. 关闭swap</strong></li>
</ul>
<div class="code sh highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;</span> <span class="n">swapoff</span> <span class="o">-</span><span class="n">a</span> <span class="o">&amp;&amp;</span> <span class="n">sysctl</span> <span class="o">-</span><span class="n">w</span> <span class="n">vm</span><span class="o">.</span><span class="n">swappiness</span><span class="o">=</span><span class="mi">0</span>
<span class="n">vm</span><span class="o">.</span><span class="n">swappiness</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">或</span> <span class="n">swapoff</span> <span class="o">-</span><span class="n">a</span>

<span class="c1">#/etc/fstab也要注解掉SWAP挂载。</span>
<span class="n">sed</span> <span class="o">-</span><span class="n">i</span> <span class="s1">&#39;s/.*swap.*/#&amp;/&#39;</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">fstab</span>
</pre></div>
</div>
<ul class="simple">
<li><strong>5. 配置系统内核参数</strong></li>
</ul>
<div class="code sh highlight-default notranslate"><div class="highlight"><pre><span></span>使流过网桥的流量也进入iptables/netfilter框架中，在/etc/sysctl.conf中添加以下配置
cat &lt;&lt;EOF &gt; /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

sysctl -p /etc/sysctl.d/k8s.conf
</pre></div>
</div>
<ul class="simple">
<li><strong>6. 源配置</strong></li>
</ul>
<div class="code sh highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cat</span> <span class="o">&lt;&lt;</span><span class="n">EOF</span> <span class="o">&gt;</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">yum</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">d</span><span class="o">/</span><span class="n">kubernetes</span><span class="o">.</span><span class="n">repo</span>
<span class="p">[</span><span class="n">kubernetes</span><span class="p">]</span>
<span class="n">name</span><span class="o">=</span><span class="n">Kubernetes</span>
<span class="n">baseurl</span><span class="o">=</span><span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">mirrors</span><span class="o">.</span><span class="n">aliyun</span><span class="o">.</span><span class="n">com</span><span class="o">/</span><span class="n">kubernetes</span><span class="o">/</span><span class="n">yum</span><span class="o">/</span><span class="n">repos</span><span class="o">/</span><span class="n">kubernetes</span><span class="o">-</span><span class="n">el7</span><span class="o">-</span><span class="n">x86_64</span><span class="o">/</span>
<span class="n">enabled</span><span class="o">=</span><span class="mi">1</span>
<span class="n">gpgcheck</span><span class="o">=</span><span class="mi">1</span>
<span class="n">repo_gpgcheck</span><span class="o">=</span><span class="mi">1</span>
<span class="n">gpgkey</span><span class="o">=</span><span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">mirrors</span><span class="o">.</span><span class="n">aliyun</span><span class="o">.</span><span class="n">com</span><span class="o">/</span><span class="n">kubernetes</span><span class="o">/</span><span class="n">yum</span><span class="o">/</span><span class="n">doc</span><span class="o">/</span><span class="n">yum</span><span class="o">-</span><span class="n">key</span><span class="o">.</span><span class="n">gpg</span> <span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">mirrors</span><span class="o">.</span><span class="n">aliyun</span><span class="o">.</span><span class="n">com</span><span class="o">/</span><span class="n">kubernetes</span><span class="o">/</span><span class="n">yum</span><span class="o">/</span><span class="n">doc</span><span class="o">/</span><span class="n">rpm</span><span class="o">-</span><span class="n">package</span><span class="o">-</span><span class="n">key</span><span class="o">.</span><span class="n">gpg</span>
<span class="n">EOF</span>

<span class="n">yum</span> <span class="n">install</span> <span class="o">-</span><span class="n">y</span> <span class="n">epel</span><span class="o">-</span><span class="n">release</span>
<span class="n">yum</span> <span class="n">install</span> <span class="o">-</span><span class="n">y</span> <span class="n">yum</span><span class="o">-</span><span class="n">utils</span> <span class="n">device</span><span class="o">-</span><span class="n">mapper</span><span class="o">-</span><span class="n">persistent</span><span class="o">-</span><span class="n">data</span> <span class="n">lvm2</span> <span class="n">net</span><span class="o">-</span><span class="n">tools</span> <span class="n">conntrack</span><span class="o">-</span><span class="n">tools</span> <span class="n">wget</span> <span class="n">vim</span>  <span class="n">ntpdate</span> <span class="n">libseccomp</span> <span class="n">libtool</span><span class="o">-</span><span class="n">ltdl</span>
</pre></div>
</div>
</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../chapters/p01_data_structures_algorithms.html" class="btn btn-neutral float-right" title="第一章：数据结构和算法" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="../chapters/k8s.html" class="btn btn-neutral" title="k8s 安装" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2017, 熊能.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../',
            VERSION:'3.0.0',
            LANGUAGE:'None',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>

  

  <script type="text/javascript" src="../_static/js/theme.js"></script>

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>